/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: 与AI设备(D芯片)相关dnn,runtime,drv等接口适配
 * Author: ligang
 * Create: 2022-02-24
 */

#include <adapter_tdt.h>
#include "log.h"
#include "workflow_pub.h"

using namespace hccl;

HcclResult hrtOpenTsd(u32 deviceLogicId, u32 rankSize)
{
#ifndef HCCD
    tsd::TSD_StatusT tdtStatus = DlTdtFunction::GetInstance().dlTsdOpen(deviceLogicId, rankSize);
    if (tdtStatus != tsd::TSD_OK) {
        HCCL_ERROR("[Open][Tsd]Open TsdClient failed, tdt error code : %u, error deviceLogicId[%u], "\
            "rankSize[%u]", tdtStatus, deviceLogicId, rankSize);
        return HCCL_E_UNAVAIL;
    }
    HCCL_INFO("Open TsdClient success. deviceLogicId[%u], rankSize[%u]", deviceLogicId, rankSize);
    return HCCL_SUCCESS;
#else
    HCCL_ERROR("[hrtOpenTsd]Does not support this interface.");
    return HCCL_E_NOT_SUPPORT;
#endif
}

HcclResult hrtTsdProcessOpen(u32 deviceLogicId, ProcOpenArgs *openArgs)
{
    tsd::TSD_StatusT tdtStatus = DlTdtFunction::GetInstance().dlTsdProcessOpen(deviceLogicId, openArgs);
    if (tdtStatus != tsd::TSD_OK) {
        HCCL_ERROR("[Open][TsdProcess]Open TsdProcess failed, tdt error code : %u, error deviceLogicId[%u], ",
            tdtStatus, deviceLogicId);
        return HCCL_E_UNAVAIL;
    }
    HCCL_INFO("Open TsdProcess success. deviceLogicId[%u]", deviceLogicId);
    return HCCL_SUCCESS;
}

HcclResult hrtProcessCloseSubProcList(u32 deviceLogicId, ProcStatusParam *closeList, u32 listSize)
{
    tsd::TSD_StatusT tdtStatus = DlTdtFunction::GetInstance().\
        dlProcessCloseSubProcList(deviceLogicId, closeList, listSize);
    if (tdtStatus != tsd::TSD_OK) {
        HCCL_ERROR("[Close][TsdProcess]Close TsdProcess failed, tdt error code : %u, error deviceLogicId[%u], ",
            tdtStatus, deviceLogicId);
        return HCCL_E_UNAVAIL;
    }
    HCCL_INFO("Open TsdProcess success. deviceLogicId[%u]", deviceLogicId);
    return HCCL_SUCCESS;
}

HcclResult hrtTsdCapabilityGet(uint32_t deviceLogicId, int32_t type, uint64_t ptr)
{
#ifndef HCCD
    tsd::TSD_StatusT tdtStatus = DlTdtFunction::GetInstance().\
        dlTsdCapabilityGet(deviceLogicId, type, ptr);
    if (tdtStatus != tsd::TSD_OK) {
        HCCL_ERROR("[Get][TsdCapability]Get TsdCapability failed, tdt error code: %u, error deviceLogicId[%u], ",
            tdtStatus, deviceLogicId);
        return HCCL_E_UNAVAIL;
    }
    HCCL_INFO("Get TsdCapability success. deviceLogicId[%u]", deviceLogicId);
    return HCCL_SUCCESS;
#else
    HCCL_ERROR("[hrtTsdCapabilityGet]Does not support this interface.");
    return HCCL_E_NOT_SUPPORT;
#endif
}
